package com.wl156.activities.find;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParserException;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.wl156.adapters.GoodAdapter;
import com.wl156.lite.R;

public class FindGoodMessageResult extends FindResultBase {

	String endLocationLv1;
	String endLocationLv2;
	String endLocationLv3;
	String goodName = "";
	String truckTonnage;
	String truckTonnageSymBol;
	String truckLength;
	String truckLengthSymbol;
	String setOffDate = "";
	String setOffDateSymbol = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mHeaderStub.setLayoutResource(R.layout.item_good_header);
		mHeaderStub.inflate();

		Bundle extras = getIntent().getExtras();
		goodName = extras.getString("goodName");
		startLocationLv1 = extras.getString("startLocationLv1");
		startLocationLv2 = extras.getString("startLocationLv2");
		startLocationLv3 = extras.getString("startLocationLv3");
		endLocationLv1 = extras.getString("endLocationLv1");
		endLocationLv2 = extras.getString("endLocationLv2");
		endLocationLv3 = extras.getString("endLocationLv3");
		truckTonnage = extras.getString("truckTonnage");
		truckTonnageSymBol = extras.getString("truckTonnageSymBol");
		truckLength = extras.getString("truckLength");
		truckLengthSymbol = extras.getString("truckLengthSymbol");

		new FindTask(type).execute();
	}

	@Override
	protected String getFindName() {
		return "货讯";
	}

	@Override
	protected Class getFindActivity() {
		return FindGood.class;
	}

	@Override
	protected Class getFindResultActivity() {
		return FindGoodMessageResult.class;
	}

	@Override
	protected int getPhoneIndex() {
		return 8;
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		Intent i = new Intent(FindGoodMessageResult.this, GoodInfo.class);
		i.putExtra("id", id);
		startActivity(i);
	}

	@Override
	protected void onLastItemVisible() {
		super.onLastItemVisible();

		new FindTask(type).execute();
	}

	public class FindTask extends FindTaskBase {
		public FindTask(int type) {
			super(type);
		}

		@Override
		protected void onLoadFailed() {
			super.onLoadFailed();

			new FindTask(type).execute();
		}

		@Override
		protected Object doInBackground(Void... params) {
			try {
				return mWebServiceClient.commonFindFreigthMessage(mCertificate,
						startLocationLv1, startLocationLv2, startLocationLv3,
						endLocationLv1, endLocationLv2, endLocationLv3,
						goodName, truckTonnage, truckTonnageSymBol,
						truckLength, truckLengthSymbol, setOffDate,
						setOffDateSymbol, mCurrentPageIndex, countPerPage);
			} catch (IOException e) {
				return e;
			} catch (XmlPullParserException e) {
				return e;
			}
		}
	}

	@Override
	protected Class getAdapter() {
		return GoodAdapter.class;
	}

}
